﻿using System.Drawing;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Compiled.Win8StartWPF
{
	public static class Extensions
	{
		public static ImageSource ToImageSource(this Icon icon)
		{
			ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
					icon.Handle,
					Int32Rect.Empty,
					BitmapSizeOptions.FromEmptyOptions());

			return imageSource;
		}

		public static ImageSource ToImageSource(this Bitmap img)
		{
			ImageSource imageSource = Imaging.CreateBitmapSourceFromHBitmap(
					img.GetHbitmap(),
					System.IntPtr.Zero,
					Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());

			return imageSource;
		}

	}
}